PROGRAM main
  VAR
    // 启动按钮
    bStartButton AT %IX0.0 : BOOL;
    // 停止按钮
    bStopButton AT %IX0.1 : BOOL;
    // 电机1控制输出
    bMotor1Switch AT %QX0.1 : BOOL;
    // 电机2控制输出
    bMotor2Switch AT %QX0.2 : BOOL;
    // 电机3控制输出
    bMotor3Switch AT %QX0.3 : BOOL;
    // 电机1停止标志
    bMotor1Stop : BOOL;
    // 电机2停止标志
    bMotor2Stop : BOOL;
    // 电机3停止标志
    bMotor3Stop : BOOL;
    // 启动定时器1
    aStartTimer1 : TON;
    // 启动定时器2
    aStartTimer2 : TON;
    // 停止定时器1
    aStopTimer1 : TON;
    // 停止定时器2
    aStopTimer2 : TON;
  END_VAR

  VAR CONSTANT
    // 延迟时间
    tDelay : TIME := T#10s;
  END_VAR

  bMotor1Switch := (bStartButton OR bMotor1Switch) AND NOT bMotor1Stop;
  aStartTimer1(IN := bMotor1Switch, PT := tDelay);
 
  bMotor2Switch := (aStartTimer1.Q OR bMotor2Switch) AND NOT bMotor2Stop;
  aStartTimer2(IN := bMotor2Switch, PT := tDelay);
  
  bMotor3Switch := (aStartTimer2.Q OR bMotor3Switch) AND NOT bMotor3Stop;

  bMotor1Stop := (bStopButton OR bMotor1Stop) AND NOT bStartButton;
  
  aStopTimer1(IN := bMotor1Stop, PT := tDelay);
  bMotor2Stop := aStopTimer1.Q;
  
  aStopTimer2(IN := bMotor2Stop, PT := tDelay);
  bMotor3Stop := aStopTimer2.Q;
END_PROGRAM
